/**
 * 
 */
package com.log.database.util;

import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

/**
 * @author vu.hoang.le
 * 
 */
public class LogDatabaseHelper extends SQLiteOpenHelper {

	private final String TAG = LogDatabaseHelper.class.getSimpleName();

	public LogDatabaseHelper(Context context) {
		super(context, LogSQLQuery.DATABASE_NAME, null,
				LogSQLQuery.DATABASE_VERSION);

		Log.i("vulh_" + TAG, "Constructor LogDatabaseHelper successful!");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.database.sqlite.SQLiteOpenHelper#onCreate(android.database.sqlite
	 * .SQLiteDatabase)
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		try {
			db.execSQL(LogSQLQuery.TBL_USER_LOGIN);
			Log.i("vulh_" + TAG, "onCreate");
		} catch (SQLException e) {
			Log.e("vulh_" + TAG, e.getMessage());
		}
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite
	 * .SQLiteDatabase, int, int)
	 */
	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		Log.i("vulh_LogDatabaseHelper_onUpgrade",
				"Updating database from version: " + oldVersion + " to "
						+ newVersion + ", which will destroy old data");
		db.execSQL(LogSQLQuery.TBL_USER_LOGIN_DROP);
		onCreate(db);
	}

}
